package com.program.facesigninsystem.util;

import org.springframework.util.DigestUtils;

/**
 * @author sxw
 */
public class EncryptionUtil {
    public static String[] md5Encrypt(String salt1,String content) {
        StringBuilder salt = new StringBuilder();
        if("".equals(salt1)){
            String model = "abcdefghijklmnopqrstuvwxyz1234567890";
            char[] m = model.toCharArray();
            for (int i = 0; i < 6; i++) {
                char c = m[(int) (Math.random() * 36)];
                salt.append(c);
            }
        }else {
            salt=new StringBuilder(salt1);
        }

        String before = salt.substring(0, 3);
        String after = salt.substring(3, 6);
        String str = before + content + after;
        String md5Str = DigestUtils.md5DigestAsHex(str.getBytes()).toUpperCase();
        return new String[]{salt.toString(),md5Str};
    }
}
